Determining Whether Two Shapes Touch
QuickDraw GX provides three functions to help you determine whether the areas of two shapes touch--that is, whether they intersect, even at a single point.
This section shows examples of using the
- The
GXTouchesRectanglePoint
function determines whether a point lies within the boundaries of a rectangle.- The
GXTouchesBoundsShape
function determines whether the area covered by a shape touches the area covered a rectangle.- The
GXTouchesShape
function determines whether one shape touches another shape
GXTouchesShape
function. The sample function in Listing 4-10 defines a rectangle and a circular path shape to use for these examples.Listing 4-10 Creating a rectangle and a circular path shape
void CreateBoxedCircle(void) { gxShape aLargeCircle; static gxRectangle largeBounds = {ff(50), ff(50), ff(150), ff(150)}; static long largeCircleGeometry[] = {1,/* number of contours */ 4,/* number of points */ 0xF0000000, /* 1111 ... */ ff(50), ff(50), /* off */ ff(150), ff(50), /* off */ ff(150), ff(150),/* off */ ff(50), ff(150)};/* off */ aLargeCircle = GXNewPaths((gxPaths *) largeCircleGeometry); GXSetShapeFill(aLargeCircle, gxClosedFrameFill); GXDrawRectangle(&largeBounds, gxClosedFrameFill); GXDrawShape(aLargeCircle); GXDisposeShape(aLargeCircle); }The result of this function is shown in Figure 4-46.Figure 4-46 A rectangle containing a circular path
You can call the
GXTouchesBoundsShape
function to test whether the rectangle and the path shape defined in Listing 4-10 touch:
GXTouchesBoundsShape(&largeBounds, aLargeCircle)This function call returnstrue
; the area of the rectangle does intersect the area of the path.When calculating whether a rectangle and a shape intersect, the
GXTouchesBoundsShape
function assumes that the rectangle has an even-odd shape fill. The following code defines another, smaller, path shape to test for intersection with the rectangle defined in Listing 4-10:
gxShape aSmallCircle; static long smallCircleGeometry[] = {1, /* number of contours */ 4, /* number of points */ 0xF0000000, ff(65), ff(65), /* off */ ff(135), ff(65), /* off */ ff(135), ff(135),/* off */ ff(65), ff(135)};/* off */ aSmallCircle = GXNewPaths((gxPaths *) smallCircleGeometry); GXSetShapeFill(aSmallCircle, gxClosedFrameFill);The call
GXTouchesBoundsShape(&largeBounds, aSmallCircle);returnstrue
because the smaller path shape touches the area contained by the rectangle, as shown in Figure 4-47.Figure 4-47 A rectangle that touches a circular path shape
The
GXTouchesBoundsShape
function returnstrue
even if the rectangle and the path shape share only an edge or even a single point. For example, if you move the small circle to the right by a distance of 85.0 points by calling
GXMoveShape(aSmallCircle, ff(85), 0);as depicted in Figure 4-48, then the call
GXTouchesBoundsShape(&largeBounds, aSmallCircle)still returnstrue
.Figure 4-48 A rectangle and a circular path touching at a single point
The
GXTouchesShape
function works similarly to theGXTouchesBoundsShape
function, but it determines whether any two shapes intersect.As an example, if you give the path shapes defined earlier in this section the even-odd shape fill by calling
GXSetShapeFill(aLargeCircle, gxEvenOddFill); GXSetShapeFill(aSmallCircle, gxEvenOddFill);then the call
GXContainsShape(aLargeCircle, aSmallCircle)returnstrue
; the small path intersects the area contained in the large path, as shown in Figure 4-49.Figure 4-49 A large circular path shape touching a smaller circular path shape
For information about the
GXTouchesRectanglePoint
function, see page 4-96. For more information about theGXTouchesBoundsShape
function and theGXTouchesShape
function, see page 4-97 and page 4-98, respectively.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help